function createChannel(){
  let currentTakers = []; //当前的监听者

  function take(actionType,taker){
    taker.actionType = actionType;
    taker.cancel = ()=>{
      currentTakers = currentTakers.filter(item => item !== taker);
    }
    currentTakers.push(taker);
  }

  function publish(action){
    currentTakers.forEach(taker/*如果这个taker是take订阅的,那么就是runSaga里的next*/=>{
      if(taker.actionType===action.type){
        taker.cancel();
        taker(action) //相当于runSaga里 ---> next(action/*←是个对象 {type,payload}*/), 也就是生成器里 const r = take(xxx), r的结果
      }
    })
  }

  return {take, publish}
}

export default createChannel;
